package ink.lovejinhu.swardToOffer;

/**
 * @author jinhu
 * created 2021-08-11 17:55
 */
public class Offer_050 {
    int[] v0 = new int[26];
    int[] v1 = new int[26];

    public char firstUniqChar(String s) {
        if (s == null || s.length() == 0) {
            return ' ';
        }
        for (int i = 0; i < s.length(); i++) {
            if (v0[s.charAt(i) - 'a'] == 0) {
                v0[s.charAt(i) - 'a']++;
                v1[s.charAt(i) - 'a'] = i;
            } else {
                v0[s.charAt(i) - 'a']++;
            }
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < 26; i++) {
            if (v0[i] == 1) {
                if (v1[i] < min) {
                    min = v1[i];
                }
            }
        }
        return min==Integer.MAX_VALUE?' ':s.charAt(min);

    }
}
